package com.webserver.core;

import com.webserver.http.HttpContext;
import com.webserver.http.HttpServletRequest;
import com.webserver.http.HttpServletResponse;

import javax.swing.text.html.HTML;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 处理请求环节
 */
public class DispatcherServlet {

    public void service(HttpServletRequest request, HttpServletResponse response){
        String path = request.getUri();
        System.out.println("请求路径" + path);
        File file = new File("./webapps" + path);
        if (file.isFile()) {//用户请求的是一个文件
            response.setEntify(file);

        } else {
            response.setStatusCode(404);
            response.setStatusReason("NotFound");
            file = new File("./webapps/root/404.html");
            response.setEntify(file);
        }
        response.putHeader("Server","WebServer");
    }
}
